<?php
// 新建订单


require_once $this->website['path']['action'] . '/zfb/shops/token.php';
$json = array('status'=>'ok','msg'=>'','data'=>'');

$params = $this->params();


// $this->website['class']['db']
// ->exec("
//   insert into product_order(uid,sid,createtime,leaseTerm,allDeposit,params,invoice,note,tit,province,city,district,street,address,phone) values(1,8,1608881940,180,44444,'{\"product\":{\"id\":25,\"tid\":138,\"sid\":8,\"sales\":12,\"inventory\":112,\"createtime\":1608686792,\"price\":12300,\"priceall\":12300,\"pricetm\":12,\"pricemin\":0,\"pricemax\":0,\"deposit\":44444,\"coupon\":0,\"huabei\":0,\"buyout\":1,\"shutdown\":0,\"shopsrecommend\":1,\"unit\":\"套\",\"tit\":\"BBAAB\",\"image\":\"https://zfb.yirenzuji.com/data/upload/image/2020/12/23/56cb9a37ac395cde800f1e47f27dc86f.jpg\",\"leaseTerm\":[\"180\",\"365\"],\"prices\":[{\"tit\":\"C\",\"price\":\"9999900.00\",\"prices\":\"\",\"inventory\":999999},{\"tit\":\"a\",\"price\":\"999900.00\",\"inventory\":999999},{\"tit\":\"b\",\"price\":\"999900.00\",\"inventory\":999999},{\"tit\":\"d\",\"price\":\"99999900.00\",\"inventory\":999999}],\"args\":[{\"k\":\"A\",\"v\":\"B\"}]},\"period\":6,\"detail\":[{\"id\":681,\"pid\":25,\"num\":0,\"image\":\"https://zfb.yirenzuji.com/data/upload/image/2020/12/23/d3a128c75552337d96a43de9bdc54776.jpg\"},{\"id\":682,\"pid\":25,\"num\":0,\"image\":\"https://zfb.yirenzuji.com/data/upload/image/2020/12/23/230151350d9e53526b95f0b437c132b8.jpg\"},{\"id\":683,\"pid\":25,\"num\":0,\"image\":\"https://zfb.yirenzuji.com/data/upload/image/2020/12/23/26b9c0b1d56ecfdacb0dc7671cbbfe19.jpg\"},{\"id\":684,\"pid\":25,\"num\":0,\"image\":\"https://zfb.yirenzuji.com/data/upload/image/2020/12/23/49873f2968d7eea823feef8280b47c14.jpg\"}],\"selectNum\":1,\"leaseTerm\":\"180\",\"selectPrice\":{\"tit\":\"C\",\"price\":999990000,\"prices\":\"\",\"inventory\":999999},\"allDeposit\":44444}','','','Eric','浙江省','杭州市','西湖区','西溪路','黄龙时代 不放自提柜 送到家 送到家 送到家 送到家','158***5632')
// ");

$id= $this->website['class']['db']
     ->table('product_order')
     ->field(
      'uid',
      'sid',
      'createtime',
      'leaseTerm',
      'allDeposit',
      'params',
      'invoice',
      'cont',
      'tit',
      'province',
      'city',
      'district',
      'street',
      'address',
      'phone'
    )
    ->value(
      $params['uid'],
      $params['sid'],
      $_SERVER['REQUEST_TIME'],
      $params['leaseTerm'],
      $params['allDeposit'],
      $params['params'],
      $params['invoice'],
      $params['cont'],
      $params['tit'],
      $params['province'],
      $params['city'],
      $params['district'],
      $params['street'],
      $params['address'],
      $params['phone']
    )->insert();
 


if($id){
  $this->website['class']['db']
     ->table('product_order')
     ->field('orderid')
     ->value(date('Ymd').$id)
     ->where('id=?',$id)
     ->limit(1)
     ->update();

  $json['data'] = $id;
  $json['msg'] = '订单提交成功';
}else{
  $json['msg'] = '订单提交失败';
  $json['status'] = 'error';
}




$this->json_encode_encrypt($json);